package com.achf.siap.cd.entidade.membro;

import com.achf.siap.cd.entidade.base.Entidade;
import com.achf.siap.cd.entidade.local.Endereco;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Aureliano
 */
@Entity
@Table(schema="siap", name="usuario")
public class Usuario implements Entidade {

    @Id
    @SequenceGenerator(name="usuario_seq")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="usuario_seq")
    @Column(name="id", nullable=false)
    private Long id;

    @Column(name="login", nullable=false, length=20, unique=true)
    private String login;

    @Column(name="senha", nullable=false, length=20)
    private String senha;

    @Column(name="email", nullable=true, length=100)
    private String email;

    @Column(name="data_cadastro", nullable=false)
    @Temporal(TemporalType.DATE)
    private Date dataCadastro;

    @ManyToMany(targetEntity=Perfil.class, fetch=FetchType.LAZY)
    private List<Perfil> perfis;

    @OneToOne(targetEntity=Endereco.class, cascade={CascadeType.ALL})
    private Endereco endereco;

    public Usuario() {
        super();
    }

    public Date getDataCadastro() {
        return dataCadastro;
    }

    public void setDataCadastro(Date dataCadastro) {
        this.dataCadastro = dataCadastro;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public List<Perfil> getPerfis() {
        return perfis;
    }

    public void setPerfis(List<Perfil> perfis) {
        this.perfis = perfis;
    }

    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        this.endereco = endereco;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Usuario other = (Usuario) obj;
        if ((this.login == null) ? (other.login != null) : !this.login.equals(other.login)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 59 * hash + (this.login != null ? this.login.hashCode() : 0);
        return hash;
    }
}